from fastapi import WebSocket
from typing import Dict, List

class ConnectionManager:
    def __init__(self):
        # 使用字典来存储活跃的连接，键是 client_id
        self.client_id = None
        self.active_connections: Dict[str, WebSocket] = {}

    async def connect(self, websocket: WebSocket, client_id: str):
        await websocket.accept()
        self.client_id = client_id
        self.active_connections[client_id] = websocket

    def disconnect(self, client_id: str):
        if client_id in self.active_connections:
            del self.active_connections[client_id]

    async def send_audio_chunk(self, client_id: str, chunk: bytes):
        if client_id in self.active_connections:
            websocket = self.active_connections[client_id]
            await websocket.send_bytes(chunk)